Linux Journal August 2018 by Linux Journal
Author:Linux Journal [Journal, Linux]
Language: eng
Format: epub, mobi
Publisher: Linux Journal LLC
Published: 2018-07-31T05:00:00+00:00
Using the LXC Utilities
For most modern Linux distributions, the kernel is enabled with cgroups, but you most likely still will need to install the LXC utilities.
If you're using Red Hat or CentOS, you'll need to install the EPEL repositories first. For other distributions, such as Ubuntu or Debian, simply type:
$ sudo apt-get install lxc
Now, before you start tinkering with those utilities, you need to configure your environment. And before doing that, you need to verify that your current user has both a uid and gid entry defined in /etc/subuid and /etc/subgid:
$ cat /etc/subuid petros:100000:65536 $ cat /etc/subgid petros:100000:65536
Create the ~/.config/lxc directory if it doesn't already exist, and copy the /etc/lxc/default.conf configuration file to ~/.config/lxc/default.conf. Append the following two lines to the end of the file:
lxc.id_map = u 0 100000 65536 lxc.id_map = g 0 100000 65536
It should look something like this:
$ cat ~/.config/lxc/default.conf lxc.network.type = veth lxc.network.link = lxcbr0 lxc.network.flags = up lxc.network.hwaddr = 00:16:3e:xx:xx:xx lxc.id_map = u 0 100000 65536 lxc.id_map = g 0 100000 65536
Append the following to the /etc/lxc/lxc-usernet file (replace the first column with your user name):
petros veth lxcbr0 10
The quickest way for these settings to take effect is either to reboot the node or log the user out and then log back in.
Once logged back in, verify that the veth networking driver is currently loaded:
$ lsmod|grep veth veth 16384 0
If it isn't, type:
$ sudo modprobe veth
You now can use the LXC utilities to download, run and manage Linux containers.
Next, download a container image and name it "example-container". When you type the following command, you'll see a long list of supported containers under many Linux distributions and versions:
$ sudo lxc-create -t download -n example-container
You'll be given three prompts to pick the distribution, release and architecture. I chose the following:
Distribution: ubuntu Release: xenial Architecture: amd64
Once you make a decision and press Enter, the rootfs will be downloaded locally and configured. For security reasons, each container does not ship with an OpenSSH server or user accounts. A default root password also is not provided. In order to change the root password and log in, you must run either an lxc-attach or chroot into the container directory path (after it has been started).
Start the container:
$ sudo lxc-start -n example-container -d
The -d option dæmonizes the container, and it will run in the background. If you want to observe the boot process, replace the -d with -F, and it will run in the foreground, ending at a login prompt.
You may experience an error similar to the following:
$ sudo lxc-start -n example-container -d lxc-start: tools/lxc_start.c: main: 366 The container failed to start. lxc-start: tools/lxc_start.c: main: 368 To get more details, run the container in foreground mode. lxc-start: tools/lxc_start.c: main: 370 Additional information can be obtained by setting the --logfile and --logpriority options.
If you do, you'll need to debug it by running the lxc-start service in the foreground:
$ sudo lxc-start -n example-container -F lxc-start: conf.c: instantiate_veth: 2685 failed to create veth pair (vethQ4NS0B and vethJMHON2): Operation not supported lxc-start: conf.c: lxc_create_network: 3029 failed to create netdev lxc-start: start.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25287)
Hello! Python by Anthony Briggs(24338)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23432)
Kotlin in Action by Dmitry Jemerov(22511)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21975)
Dependency Injection in .NET by Mark Seemann(21845)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20711)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19523)
Grails in Action by Glen Smith Peter Ledbrook(18605)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17033)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15843)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13690)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11853)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11151)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10621)
Hit Refresh by Satya Nadella(9199)
The Kubernetes Operator Framework Book by Michael Dame(8570)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8400)
Robo-Advisor with Python by Aki Ranin(8360)